package com.woniu.shirocore;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.env.BasicIniEnvironment;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

/**
 * @author Rain
 * @Description :
 * @date 2022/09/05 15:56
 */
public class RealmBasicDemo {

    public static void main(String[] args) {
        BasicIniEnvironment basicIniEnvironment = new BasicIniEnvironment("classpath:ini/shiro-realm.ini");
        SecurityManager securityManager = basicIniEnvironment.getSecurityManager();
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();

        subject.login(new UsernamePasswordToken("rain", "123456"));

        System.out.println(subject.getPrincipal() + "登陆成功" + subject.isAuthenticated());

        subject.checkRole("manager");
        subject.checkPermission("manager:find");
    }
}
